import {Request} from "@/request/request"
import utils from "@/utils/tool.js"
const $request = new Request({
    host: utils.data.get('server_url'),  //接口地址
    // host: 'http://192.168.2.225:57300',	
	timeout: 60000,   //超时时间
	showLoadingDelay: 2000, // 延迟多长时间显示loading效果，为0时则直接显示
	loadingText: "加载中",  // 加载中文字
	showError: true,  // 遇到错误时是否提示
	defaultError: "抱歉！网络请求失败",  // 默认错误消息
	before(config) {
		// config.header['Token'] = '123456789'; 
		return config;
	},
	after(requestTaskPromise) {
		return requestTaskPromise
			.then(ret => ret)
			.catch(console.log);
	},
	validator(response) {   //状态码
		if (response.getStatusCode() !== 200) {
			throw new Error("状态码错误");
		}
	}
});


const apis = {
	 
	login: {
		url: `/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=login&session=AudioStation&format=sid`,
		name: "用户登录",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	logout: {
		url: `/webapi/auth.cgi?api=SYNO.API.Auth&version=1&method=logout&session=AudioStation`,
		name: "用户登出",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	
	
	
	get_base_info: {
		url: `/webapi/query.cgi?api=SYNO.Core.System.SystemHealth&version=1&method=get`,
		name: "获取服务器基本信息",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	 
	
	get_music_list:{
		url: `/webapi/AudioStation/song.cgi?api=SYNO.AudioStation.Song&version=3&method=list`,
		name: "获取音乐列表",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	get_music_cover:{
		url: `/webapi/AudioStation/cover.cgi?api=SYNO.AudioStation.Cover&version=3&method=getsongcover`,
		name: "获取音乐封面",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	play_music:{
		url: `/webapi/AudioStation/stream.cgi/0.flac?api=SYNO.AudioStation.Stream&version=2&method=stream`,
		name: "获取音乐播放地址",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	get_lyric:{
		url: `/webapi/AudioStation/lyrics.cgi?api=SYNO.AudioStation.Lyrics&version=2&method=getlyrics`,
		name: "获取音乐歌词",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	search_lyric:{
		url: `/webapi/AudioStation/lyrics_search.cgi?api=SYNO.AudioStation.LyricsSearch&version=2&method=searchlyrics&additional=full_lyrics`,
		name: "搜索音乐歌词",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	get_playlist:{
		url: `/webapi/AudioStation/playlist.cgi?api=SYNO.AudioStation.Playlist&version=3&method=list`,
		name: "获取播放列表",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	get_playlist_info:{
		url: `/webapi/AudioStation/playlist.cgi?api=SYNO.AudioStation.Playlist&version=3&method=getinfo`,
		name: "获取歌单音乐",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	add_playlist:{
		url: `/webapi/AudioStation/playlist.cgi?api=SYNO.AudioStation.Playlist&version=3&method=create`,
		name: "新建歌单",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	save_playlist_name:{
		url: `/webapi/AudioStation/playlist.cgi?api=SYNO.AudioStation.Playlist&version=3&method=rename`,
		name: "歌单重命名",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	delete_playlist_name:{
		url: `/webapi/AudioStation/playlist.cgi?api=SYNO.AudioStation.Playlist&version=3&method=delete`,
		name: "歌单删除",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	delete_music:{
		url: `/webapi/entry.cgi?api=SYNO.FileStation.Delete&version=2&method=start`,
		name: "歌曲删除",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	
	download_music:{
		url: `/webapi/AudioStation/download.cgi?api=SYNO.AudioStation.Download&version=1&method=download`,
		name: "下载歌曲",
		request: async function(params){
			return await $request.download(this.url, params);
		}
	},
	
	updatesongs:{
		url: `/webapi/AudioStation/playlist.cgi?api=SYNO.AudioStation.Playlist&version=3&method=updatesongs`,
		name: "添加到歌单",
		request: async function(params){
			return await $request.get(this.url, params);
		}
	},
	
	
}

export default apis;